<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class UserLevel extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 可搜索字段
     * @var string[]
     */

    public $searchable = [
        'user_id',
        'merchant_id',
        'level_id',
        'grade',
        'valid_time',
        'remind',
        'is_forever',
        'status',
        'promoter_id'
    ];
    /**
     *  可批量赋值字段
     * @var string[]
     */
    public $fillable = [
        'user_id',
        'merchant_id',
        'level_id',
        'grade',
        'valid_time',
        'promoter_id'
    ];
    /**
     * 可排序字段
     * @var string[]
     */

    public $sortable = [
        'user_id',
        'merchant_id',
        'level_id',
        'grade',
        'discount',
        'promoter_id',
    ];
    /**
     * 默认排序字段
     * @var string[]
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 用户所属的等级
     */
    public function level(){
        return $this->belongsTo(User::class,'user_id','id');

    }
}
